package com.captain.leetcode.二叉树;

import com.captain.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author captain
 * @Des Subsequent
 * 先左叶子节点 - 右 再父节点
 * @Date 2021/7/20 22:06
 */
public class 二叉树的后序遍历145 {

    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        subsequent(root, res);
        return res;
    }

    //后续遍历
    private void subsequent(TreeNode root, List<Integer> res) {
        if (root == null) return;
        subsequent(root.left, res);
        subsequent(root.right, res);
        res.add(root.val);
    }
}
